package cn.bdqn.controller;

import cn.bdqn.bean.result.Result;
import cn.bdqn.bean.result.ResultCode;
import cn.bdqn.bean.result.ResultGenerator;
import cn.bdqn.domain.Bunk;
import cn.bdqn.service.BunkService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/HM/bunk")
public class BunkController {

    @Resource
    private BunkService bunkService;


    Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * 获取床位列表
     * @param roomId 房间号
     * @return
     */
    @GetMapping("/getBunkList/{roomId}")
    public Result<Map<String, Object>> getBunkList(@PathVariable("roomId") Integer roomId){
        Map<String, Object> data = new HashMap<>();
        try {
            logger.info("进入了 getBunkList(获取床位列表的方法)");
            List<Bunk> bunks = bunkService.queryByRoomId(roomId);
            data.put("bunks", bunks);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("getBunkList(获取床位列表的方法) 抛出了异常:" + e.getMessage());
            return ResultGenerator.genFailResult("网络异常", ResultCode.INTERNAL_SERVER_ERROR);
        }
        return ResultGenerator.genSuccessResult(data);
    }

}
